<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="租户" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="租户"></el-input>
    </el-form-item>
    <el-form-item label="是否启用服务费1用2不" prop="serviceConstStatus">
      <el-input v-model="dataForm.serviceConstStatus" placeholder="是否启用服务费1用2不"></el-input>
    </el-form-item>
    <el-form-item label="服务费率" prop="serviceConstRatio">
      <el-input v-model="dataForm.serviceConstRatio" placeholder="服务费率"></el-input>
    </el-form-item>
    <el-form-item label="营业时段" prop="businessTime">
      <el-input v-model="dataForm.businessTime" placeholder="营业时段"></el-input>
    </el-form-item>
    <el-form-item label="餐台区域" prop="deskArea">
      <el-input v-model="dataForm.deskArea" placeholder="餐台区域"></el-input>
    </el-form-item>
    <el-form-item label="菜品集合" prop="foods">
      <el-input v-model="dataForm.foods" placeholder="菜品集合"></el-input>
    </el-form-item>
    <el-form-item label="时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="时间"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
				disabledSubmit:false,
        dataForm: {
          id: 0,
          sellerId: '',
          serviceConstStatus: '',
          serviceConstRatio: '',
          businessTime: '',
          deskArea: '',
          foods: '',
          createTime: '',
          remark: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '租户不能为空', trigger: 'blur' }
          ],
          serviceConstStatus: [
            { required: true, message: '是否启用服务费1用2不不能为空', trigger: 'blur' }
          ],
          serviceConstRatio: [
            { required: true, message: '服务费率不能为空', trigger: 'blur' }
          ],
          businessTime: [
            { required: true, message: '营业时段不能为空', trigger: 'blur' }
          ],
          deskArea: [
            { required: true, message: '餐台区域不能为空', trigger: 'blur' }
          ],
          foods: [
            { required: true, message: '菜品集合不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '时间不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreserviceconst/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tStoreServiceConst.sellerId
                this.dataForm.serviceConstStatus = data.tStoreServiceConst.serviceConstStatus
                this.dataForm.serviceConstRatio = data.tStoreServiceConst.serviceConstRatio
                this.dataForm.businessTime = data.tStoreServiceConst.businessTime
                this.dataForm.deskArea = data.tStoreServiceConst.deskArea
                this.dataForm.foods = data.tStoreServiceConst.foods
                this.dataForm.createTime = data.tStoreServiceConst.createTime
                this.dataForm.remark = data.tStoreServiceConst.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreserviceconst/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'serviceConstStatus': this.dataForm.serviceConstStatus,
                'serviceConstRatio': this.dataForm.serviceConstRatio,
                'businessTime': this.dataForm.businessTime,
                'deskArea': this.dataForm.deskArea,
                'foods': this.dataForm.foods,
                'createTime': this.dataForm.createTime,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
										this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
